package com.android.baseconfig.base;

import android.os.Handler;
import android.os.Message;

import com.android.baseconfig.common.utils.Logc;

import java.lang.ref.WeakReference;

/**
 * Handler的基类
 *
 * @version 1.0 2015-12-16
 */
public class BaseHandler<T extends BaseHandler.BaseHandlerCallBack> extends Handler {
    WeakReference<T> wr;

    public BaseHandler(T t) {
        wr = new WeakReference<T>(t);
    }

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        T t = wr.get();

        if (t != null) {
            t.callBack(msg);
        } else {
            Logc.e("BaseHandler", "t = null");
        }
    }

    public interface BaseHandlerCallBack {
        void callBack(Message msg);
    }
}
